<?php
/**
 * Created by PhpStorm.
 * User: liujun
 * Date: 2017/11/9
 * Time: 下午2:45
 */

use PddWechat\Library\CookieLibrary;

/**
 * http://www.myleftstudio.com/reference/annotations.html
 *
 * @RoutePrefix("/user")
 */
class UserController extends \Dai\Framework\Base\BaseController
{

    /**
     * @Action("tokenCreate")
     * @Get("/token/create")
     * @Login(false)
     * @desc 注册
     */
    public function tokenCreateAction()
    {
        $tokenCrateService = new \PddWechat\Models\User\Service\TokenCreate();
        $basePageInfo = (\Phalcon\DI::getDefault())->get('basePageInfo');
        $response = $tokenCrateService->execute($basePageInfo);
        $this->cookies->set(CookieLibrary::TOKEN, $response->token, time()+ 86400);
        $this->cookies->send();
        $from = $_GET['from'];
        if( trim($from) != "") {
            header("Location: ".urldecode($from));
        } else {
            header("Location: /user/info");
        }
        exit;
    }

    /**
     * @Get("/info")
     * @Login(true)
     */
    public function infoAction()
    {
        $this->execute();
    }


    /**
     * @Action("inviteList")
     * @Get("/invite/list")
     * @format(html)
     * @desc 邀请好友记录
     */
    public function inviteListAction()
    {
        $this->execute();
    }


    /**
     * @Get("/subscribe")
     * @Login(true)
     * @desc 获取用户是否关注公众号
     */
    public function subscribeAction()
    {
        $this->execute();
    }

    /**
     * @Post("/wechat")
     * @Login(false)
     */
    public function WechatAction(){
        //return  $_GET['echostr'];//随机的字符串， 如果需要更改服务器地址, 协议也改成get
        //接收微信服务器发送POST请求到开发者服务器，携带的XML数据包
        $postData = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : file_get_contents("php://input");
        \Dai\Framework\Library\Log::info("get raw data is $postData");
        //处理xml数据包
        $xmlObj = simplexml_load_string($postData,"SimpleXMLElement",LIBXML_NOCDATA);
        $res = "";
        if($xmlObj) {
            $userWechatService = new \PddWechat\Models\User\Service\Wechat();
            $res = $userWechatService->execute($xmlObj);
        }
        \Dai\Framework\Library\Log::info("result is $res");
        echo $res;
        exit;
    }

    /**
     * @Action("directMemberNum")
     * @Get("/direct/member/num")
     * @Login(true)
     * @desc 团队直接下属成员数量
     */
    public function directMemberNumAction()
    {
        $this->execute();
    }

    /**
     * @Action("indirectMemberNum")
     * @Get("/indirect/member/num")
     * @Login(true)
     * @desc 团队间接下属成员数量
     */
    public function indirectMemberNumAction()
    {
        $this->execute();
    }

    /**
     * @Action("directMemberList")
     * @Post("/direct/member/list")
     * @Login(true)
     * @desc 团队直接下属成员列表
     */
    public function directMemberListAction()
    {
        $this->execute();
    }

    /**
     * @Action("leaderInfo")
     * @Get("/leader/info")
     * @Login(true)
     * @desc 上级领导信息
     */
    public function leaderInfoAction()
    {
        $this->execute();
    }

    /**
     * @Action("dataCenter")
     * @Get("/data/center")
     * @Login(true)
     * @desc 个人中心首页数据中心接口
     */
    public function dataCenterAction()
    {
        $this->execute();
    }

    /**
     * @Action("teamCount")
     * @Get("/team/count")
     * @Login(true)
     * @desc 团队人数统计展示(日，周，月)
     */
    public function teamCountAction() {
        $this->execute();
    }

    /**
     * @Action("bindBankCard")
     * @Post("/bind/card")
     * @Login(true)
     * @desc 绑定用户信用卡
     */
    public function bindBankCardAction() {
        $this->execute();
    }

    /**
     * @Action("withdrawCash")
     * @Post("/withdraw/cash")
     * @Login(true)
     * @desc 提现申请操作
     */
    public function withdrawCashAction() {
        $this->execute();
    }

    /**
     * @Action("ackWithdraw")
     * @Get("/ack/withdraw")
     * @Login(true)
     * @desc 确认已转账
     */
    public function ackWithdrawAction() {
        $this->execute();
    }

    /**
     * @Action("userWithdrawList")
     * @Post("/withdraw/list")
     * @Login(true)
     * @desc 所有用户提现列表
     */
    public function userWithdrawListAction() {
        $this->execute();
    }

    /**
     * @Action("userWithdrawMoney")
     * @Get("/withdraw/data")
     * @Login(true)
     * @desc 用户提现中以及已提现数据
     */
    public function userWithdrawMoneyAction() {
        $this->execute();
    }

    /**
     * @Action("userPersonWithdrawList")
     * @Get("/withdraw/person/list")
     * @Login(true)
     * @desc 用户个人提现列表
     */
    public function userPersonWithdrawListAction() {
        $this->execute();
    }

    /**
     * @Action("userBankCardInfo")
     * @Get("/bank/card/info")
     * @Login(true)
     * @desc 用户个人银行卡相关信息
     */
    public function userBankCardInfoAction() {
        $this->execute();
    }
}
